<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高级音乐播放器</title>
    <!-- 引入Font Awesome图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 全局样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            background-color: #000; /* 纯黑色背景 */
            font-family: 'Poppins', Montserrat, sans-serif;
            color: white;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
            overflow-x: hidden;
        }
        
        /* 添加微弱噪点纹理 */
        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 1px);
            background-size: 10px 10px;
            z-index: -1;
        }
        
        /* 主容器 */
        .player-container {
            width: 400px;
            max-width: 90%;
            background: linear-gradient(to bottom, #0a2e5a, #000);
            border-radius: 20px;
            box-shadow: rgba(0, 0, 0, 0.6) 0px 10px 30px;
            padding: 30px;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
        }
        
        /* 专辑封面区域 */
        .album-art {
            width: 200px;
            height: 200px;
            margin-bottom: 25px;
            border-radius: 15px;
            overflow: hidden;
            position: relative;
            box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
        }
        
        .album-art img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
        }
        
        .album-art:hover img {
            transform: scale(1.05);
        }
        
        /* 歌曲信息面板 */
        .song-info {
            text-align: center;
            margin-bottom: 25px;
            width: 100%;
        }
        
        .song-title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 8px;
            letter-spacing: 1px;
            text-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
        }
        
        .artist {
            font-size: 16px;
            color: #CCCCCC;
            letter-spacing: 0.5px;
            font-variant: small-caps;
            text-shadow: 0 0 3px rgba(255, 255, 255, 0.5);
        }
        
        /* 进度条样式 */
        .progress-container {
            width: 100%;
            height: 6px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 8px;
            margin-bottom: 15px;
            cursor: pointer;
            position: relative;
        }
        
        .progress-bar {
            height: 100%;
            width: 0%;
            background-color: white;
            border-radius: 8px;
            transition: width 0.2s ease;
        }
        
        .time-display {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: #aaa;
            margin-top: 5px;
        }
        
        /* 控制按钮区域 */
        .controls {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
            margin: 20px 0;
        }
        
        .control-btn {
            background: none;
            border: none;
            color: #BBBBBB;
            font-size: 20px;
            cursor: pointer;
            transition: all 0.3s ease-in-out;
            padding: 8px;
            border-radius: 50%;
        }
        
        .control-btn:hover, .control-btn:focus {
            color: white;
            transform: scale(1.2);
            outline: none;
        }
        
        .play-pause-btn {
            background-color: rgba(255, 255, 255, 0.1);
            width: 50px;
            height: 50px;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 50%;
        }
        
        .play-pause-btn:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }
        
        /* 歌词显示区域 */
        .lyrics-container {
            width: 100%;
            max-height: 150px;
            overflow-y: auto;
            margin-top: 20px;
            padding: 10px;
            border-radius: 10px;
            background-color: rgba(0, 0, 0, 0.3);
        }
        
        .lyrics-line {
            font-size: 14px;
            line-height: 1.6;
            color: #888;
            margin-bottom: 8px;
            transition: all 0.3s ease;
        }
        
        .lyrics-line.active {
            color: white;
            text-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
            font-weight: bold;
        }
        
        /* 加载状态指示器 */
        .loading {
            display: none;
            text-align: center;
            padding: 20px;
            color: #ccc;
        }
        
        .spinner {
            width: 40px;
            height: 40px;
            margin: 0 auto;
            border: 4px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s linear infinite;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        /* 响应式调整 */
        @media (max-width: 480px) {
            .player-container {
                padding: 20px;
            }
            
            .album-art {
                width: 180px;
                height: 180px;
            }
        }
    </style>
</head>
<body>
    <div class="player-container">
        <!-- 专辑封面 -->
        <div class="album-art">
            <img id="albumCover" src="https://openres.xfyun.cn/xfyundoc/2025-07-25/c247b02c-affe-4c44-affa-81ba598e5420/1753430308784/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20250725155744_59.jpg" alt="专辑封面" onerror="this.src=''">
        </div>
        
        <!-- 歌曲信息 -->
        <div class="song-info">
            <h1 class="song-title">luther</h1>
            <p class="artist">Kendrick Lamar/SZA</p>
        </div>
        
        <!-- 进度条 -->
        <div class="progress-container" id="progressContainer">
            <div class="progress-bar" id="progressBar"></div>
        </div>
        <div class="time-display">
            <span id="currentTime">0:00</span> / <span id="duration">0:00</span>
        </div>
        
        <!-- 控制按钮 -->
        <div class="controls">
            <button class="control-btn" id="shuffleBtn" title="随机播放"><i class="fas fa-random"></i></button>
            <button class="control-btn" id="prevBtn" title="上一首"><i class="fas fa-step-backward"></i></button>
            <button class="control-btn play-pause-btn" id="playPauseBtn" title="播放/暂停"><i class="fas fa-play"></i></button>
            <button class="control-btn" id="nextBtn" title="下一首"><i class="fas fa-step-forward"></i></button>
            <button class="control-btn" id="repeatBtn" title="循环模式"><i class="fas fa-redo"></i></button>
        </div>
        
        <!-- 歌词区域 -->
        <div class="lyrics-container" id="lyricsContainer">
            <div class="lyrics-line">正在加载歌词...</div>
        </div>
        
        <!-- 加载指示器 -->
        <div class="loading" id="loadingIndicator">
            <div class="spinner"></div>
            <p>正在加载资源...</p>
        </div>
    </div>

    <audio id="audioPlayer" src="https://openres.xfyun.cn/xfyundoc/2025-07-25/1f8a4b19-50bf-43c0-8791-5452546c6a3d/1753438525360/beat.wav"></audio>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const audioPlayer = document.getElementById('audioPlayer');
            const playPauseBtn = document.getElementById('playPauseBtn');
            const progressBar = document.getElementById('progressBar');
            const progressContainer = document.getElementById('progressContainer');
            const currentTimeDisplay = document.getElementById('currentTime');
            const durationDisplay = document.getElementById('duration');
            const shuffleBtn = document.getElementById('shuffleBtn');
            const prevBtn = document.getElementById('prevBtn');
            const nextBtn = document.getElementById('nextBtn');
            const repeatBtn = document.getElementById('repeatBtn');
            const lyricsContainer = document.getElementById('lyricsContainer');
            const loadingIndicator = document.getElementById('loadingIndicator');
            
            // 模拟歌词数据 (实际应用中可以从API获取)
            const lyricsLines = [
                "这是第一句歌词示例",
                "第二句歌词在这里显示",
                "第三行歌词内容不同",
                "第四句更长的歌词文本用于测试换行效果",
                "第五句简短歌词",
                "最后一句结束的歌词"
            ];
            
            // 初始化歌词显示
            function initLyrics() {
                lyricsContainer.innerHTML = '';
                lyricsLines.forEach((line, index) => {
                    const lineElement = document.createElement('div');
                    lineElement.className = 'lyrics-line';
                    lineElement.textContent = line;
                    lineElement.dataset.index = index;
                    lyricsContainer.appendChild(lineElement);
                });
            }
            
            // 更新当前高亮的歌词行
            function updateCurrentLyricLine(currentTime) {
                const lines = document.querySelectorAll('.lyrics-line');
                // 简单实现：根据时间均匀分配到各行
                const totalDuration = parseFloat(audioPlayer.duration || 0);
                const segmentDuration = totalDuration / lines.length;
                const activeIndex = Math.floor(currentTime / segmentDuration);
                
                lines.forEach((line, i) => {
                    if (i === activeIndex) {
                        line.classList.add('active');
                    } else {
                        line.classList.remove('active');
                    }
                });
            }
            
            // 格式化时间为MM:SS格式
            function formatTime(seconds) {
                const mins = Math.floor(seconds / 60);
                const secs = Math.floor(seconds % 60);
                return `${mins}:${secs < 10 ? '0' : ''}${secs}`;
            }
            
            // 更新进度条和时间显示
            function updateProgress() {
                const currentTime = audioPlayer.currentTime;
                const duration = audioPlayer.duration;
                
                // 更新进度条宽度
                if (duration > 0) {
                    const progressPercentage = (currentTime / duration) * 100;
                    progressBar.style.width = `${progressPercentage}%`;
                }
                
                // 更新时间显示
                currentTimeDisplay.textContent = formatTime(currentTime);
                durationDisplay.textContent = formatTime(duration);
                
                // 更新歌词高亮
                updateCurrentLyricLine(currentTime);
            }
            
            // 设置进度条点击跳转功能
            function setProgressFromClick(e) {
                const width = this.clientWidth;
                const clickX = e.offsetX;
                const percentage = clickX / width;
                audioPlayer.currentTime = percentage * audioPlayer.duration;
            }
            
            // 播放/暂停切换
            function togglePlayback() {
                if (audioPlayer.paused) {
                    audioPlayer.play();
                    playPauseBtn.innerHTML = '<i class="fas fa-pause"></i>';
                } else {
                    audioPlayer.pause();
                    playPauseBtn.innerHTML = '<i class="fas fa-play"></i>';
                }
            }
            
            // 事件监听器
            playPauseBtn.addEventListener('click', togglePlayback);
            audioPlayer.addEventListener('timeupdate', updateProgress);
            audioPlayer.addEventListener('loadedmetadata', function() {
                durationDisplay.textContent = formatTime(audioPlayer.duration);
            });
            progressContainer.addEventListener('click', setProgressFromClick);
            
            // 其他按钮功能占位
            shuffleBtn.addEventListener('click', function() {
                alert('随机播放功能已激活');
            });
            
            prevBtn.addEventListener('click', function() {
                alert('切换到上一首歌曲');
            });
            
            nextBtn.addEventListener('click', function() {
                alert('切换到下一首歌曲');
            });
            
            repeatBtn.addEventListener('click', function() {
                const icons = ['fa-redo', 'fa-sync-alt', 'fa-undo'];
                let currentIconIndex = 0;
                
                this.classList.toggle('active');
                const newIcon = icons[(currentIconIndex + 1) % icons.length];
                this.querySelector('i').className = `fas ${newIcon}`;
                alert(`循环模式已更改为: ${newIcon === 'fa-redo' ? '单曲循环' : newIcon === 'fa-sync-alt' ? '全部循环' : '不循环'}`);
            });
            
            // 键盘可访问性支持
            document.addEventListener('keydown', function(e) {
                switch(e.code) {
                    case 'Space':
                        e.preventDefault(); // 防止页面滚动
                        togglePlayback();
                        break;
                    case 'ArrowLeft':
                        audioPlayer.currentTime = Math.max(0, audioPlayer.currentTime - 5);
                        break;
                    case 'ArrowRight':
                        audioPlayer.currentTime = Math.min(audioPlayer.duration, audioPlayer.currentTime + 5);
                        break;
                }
            });
            
            // 确保所有按钮都有焦点样式
            const buttons = document.querySelectorAll('button');
            buttons.forEach(btn => {
                btn.addEventListener('focus', function() {
                    this.style.outline = '2px solid rgba(255, 255, 255, 0.5)';
                });
                btn.addEventListener('blur', function() {
                    this.style.outline = 'none';
                });
            });
            
            // 处理图片加载错误
            const albumCover = document.getElementById('albumCover');
            albumCover.onerror = function() {
                this.src = '';
            };
            
            // 模拟网络延迟下的加载状态
            setTimeout(() => {
                loadingIndicator.style.display = 'none';
                initLyrics();
            }, 1500);
            
            // 初始显示加载状态
            loadingIndicator.style.display = 'block';
        });
    </script>
</body>
</html>
